package com.CloudDream.Command.Admin;

import com.CloudDream.Inventory.InventoryItem;
import com.CloudDream.MoonCake;
import com.handy.lib.command.IHandyCommandEvent;
import com.handy.lib.util.BaseUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

public class GiveCommand implements IHandyCommandEvent {

    @Override
    public String command() {
        return "givegift";
    }

    @Override
    public String permission() {
        return "mooncake.givegift";
    }

    @Override
    public void onCommand(CommandSender commandSender, Command command, String s, String[] args) {
        if(BaseUtil.isPlayer(commandSender).booleanValue()){
            commandSender.sendMessage(MoonCake.prefix + "§c该指令只能由控制台使用");
            return;
        }
        Player target = Bukkit.getPlayer(args[1]);
        (new BukkitRunnable(){
            @Override
            public void run() {
                if (target != null) {
                    target.getInventory().addItem(InventoryItem.getGift());
                    target.sendMessage(MoonCake.prefix + "§a管理员给你赠送一个月饼礼盒!");
                    commandSender.sendMessage("§a成功给玩家" + target.getName() + "赠送一个月饼礼盒!");
                } else {
                    commandSender.sendMessage("§c玩家不存在或不在线!");
                }
            }
        }).runTaskAsynchronously(MoonCake.getInstance());
    }
}
